<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Message extends Controller {

	private $_user_id = 0;
	private $_user = NULL;
	private $_role_rmsg = NULL;
	private $_role_wmsg = NULL;

	public function before() 
	{

		if (!Auth::instance()->logged_in())
		{
			$this->request->redirect('/');
		}
		else
		{
			$this->_user_id = Auth::instance()->get_user();
			$this->_user = ORM::factory('user')->where('id', '=', $this->_user_id)->find();
		
			$this->_role_rmsg = ORM::factory('role', 3);
			$this->_role_wmsg = ORM::factory('role', 4);
		}
			
	}

	public function action_index()
	{
		$this->response->body('Wiadomości');
	}
	
	public function action_read() 
	{
	
		if ($this->_user->has('roles', $this->_role_rmsg)) 
		{
			// Czytanie
		}
		else
		{
			// Brak uprawnień do czytania
		}
		
	}
	
	public function action_write() 
	{
	
		if ($this->_user->has('roles', $this->_role_wmsg)) 
		{
			// Pisanie (wyświetlanie forma)
		}
		else
		{
			// Brak uprawnień do pisania
		}
		
	}
	
	public function action_send() 
	{
	
		if ($this->_user->has('roles', $this->_role_wmsg))
		{
			// Wysyłanie wiadomości
		}
		else
		{
			// Brak uprawnień do pisania
			$this->request->redirect('/');
		}
		
	}
		

} // End Welcome
